﻿@page "/Admin/Config"
@using Moments.Service
@inject ConfigService ConfigService

<MExpansionPanels>
    <MExpansionPanel>
        <MExpansionPanelHeader>博主信息</MExpansionPanelHeader>
        <MExpansionPanelContent>
            <MTextField
                @bind-Value="_name"
                Outlined
                Label="昵称"
                Clearable>
            </MTextField>
            <MTextField
                @bind-Value="_avatar"
                Outlined
                Label="头像"
                Clearable>
            </MTextField>
            <MTextField
                @bind-Value="_sentence"
                Outlined
                Label="一言"
                Clearable>
            </MTextField>
        </MExpansionPanelContent>
    </MExpansionPanel>
    <MExpansionPanel>
        <MExpansionPanelHeader>网站信息</MExpansionPanelHeader>
        <MExpansionPanelContent>
            <MTextField
                @bind-Value="_title"
                Outlined
                Label="网站标题"
                Clearable>
            </MTextField>
        </MExpansionPanelContent>
    </MExpansionPanel>
    <MExpansionPanel>
        <MExpansionPanelHeader>外观设置</MExpansionPanelHeader>
        <MExpansionPanelContent>
            <MTextField
                @bind-Value="_banner"
                Outlined
                Label="头图"
                Clearable>
            </MTextField>
        </MExpansionPanelContent>
        <MExpansionPanelContent>
            <MTextField
                @bind-Value="_maximum"
                Outlined
                Label="最大描述字符"
                Clearable>
            </MTextField>
        </MExpansionPanelContent>
    </MExpansionPanel>
    <MExpansionPanel>
        <MExpansionPanelHeader>系统设置</MExpansionPanelHeader>
        <MExpansionPanelContent>
            <MTextField
                @bind-Value="_interval"
                Outlined
                Label="采集间隔(毫秒)"
                Clearable>
            </MTextField>
            <MTextField
                @bind-Value="_token"
                Outlined
                Label="系统密钥"
                Clearable>
            </MTextField>
        </MExpansionPanelContent>
    </MExpansionPanel>
</MExpansionPanels>

<MButton OnClick="Save" Style="margin: 20px">保存</MButton>


@code{
    string? _title;
    string? _interval;
    string? _token;
    string? _name;
    string? _avatar;
    string? _sentence;
    string? _banner;
    string? _maximum;
    protected override void OnInitialized()
    {
        _title = ConfigService.Get("Title");
        _interval = ConfigService.Get("Interval");
        _token = ConfigService.Get("Token");
        _name = ConfigService.Get("Name");
        _avatar = ConfigService.Get("Avatar");
        _sentence = ConfigService.Get("Sentence");
        _banner = ConfigService.Get("Banner");
        _maximum = ConfigService.Get("Maximum");

    }

    void Save()
    {
        ConfigService.Set("Title", _title);
        ConfigService.Set("Interval", _interval);
        ConfigService.Set("Token", _token);
        ConfigService.Set("Name", _name);
        ConfigService.Set("Avatar", _avatar);
        ConfigService.Set("Sentence", _sentence);
        ConfigService.Set("Banner", _banner);
        ConfigService.Set("Maximum", _maximum);
        AdminLayout.PushSnackbars(AlertTypes.Success, "保存成功");
    }


}